/**
 * 统计输入数据中每个字符出现的频率，并用矩形图显示
 */

#include <stdio.h>

#define MAX 128

int main() {
    int c, i, j, nchars[MAX];
    float sum;

    for( i = 0; i < MAX; i++) nchars[i] = 0;

    sum = 0;
    while ((c = getchar()) != EOF) {
        sum++;
        if (c >= MAX || c < 0) {
            printf("Error! character has exceeding!\ncharacter: %d", c);
            return -1;
        }
        nchars[c]++;
    }

    for(i = 0; i < MAX; i++) {
        if (nchars[i]) {
            printf("%3d[%c] %.2f%%: ", i, i, nchars[i] / sum * 100);
            for (j = 0; j < (nchars[i] / sum * 100); j++) putchar('*');
            putchar('\n');
        }
    }

    return 0;

}
